package com.wen.springbootorderserver.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.config.FanoutExchangeParser;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class OrderFanoutConfig {


    @Bean
    public FanoutExchange deadFanoutExchange(){
        return new FanoutExchange("dead_fanout_exchange",true,false);
    }

    @Bean
    public Queue deadQueue(){
        return new Queue("dead.queue",true);
    }

    @Bean
    public Binding deadBing(){
        return BindingBuilder.bind(deadQueue()).to(deadFanoutExchange());
    }


    @Bean
    public FanoutExchange orderFanoutExchange(){
        return new FanoutExchange("order_fanout_exchange",true,false);
    }

    @Bean
    public Queue orderQueue(){
        Map<String,Object> args = new HashMap<>();
        args.put("x-dead-letter-exchange","dead_fanout_exchange");
        return new Queue("order.queue",true,false,false,args);
    }


    @Bean
    public Binding orderDeadQueue(){
        return BindingBuilder.bind(orderQueue()).to(orderFanoutExchange());
    }


}
